class Solution:
    def wordSubsets(self, A: list, B: list) -> list:
        def count(string):
            array = [0 for _ in range(26)]
            for s in string:
                array[ord(s) - ord('a')] += 1
            return array

        b_counter = [0 for _ in range(26)]
        for b in B:
            counter = count(b)
            for i in range(len(counter)):
                b_counter[i] = max(b_counter[i], counter[i])

        res = []
        for a in A:
            flag = True
            a_counter = count(a)
            for i in range(len(a_counter)):
                if a_counter[i] < b_counter[i]:
                    flag = False
                    break
            if flag:
                res.append(a)
        return res
